﻿    ﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Users;
using Lists;
using Sim;

namespace Sim
{
    public class Main
    {
        public string PrintFile(string x)
        {
            StreamReader sr = new StreamReader("testmenu.txt");
            string slines;
            while (!sr.EndOfStream)
            {
                slines = sr.ReadLine();
                Console.WriteLine(slines);
            }
            return x;
        }

        public string Search(string name)
        {
            bool found = false;
            Console.Write("Team: ");
            string line;
            line = Console.ReadLine();

            StreamReader sr = new StreamReader("testmenu.txt");

            string sline = "";

            while (sline != null && !found)
            {
                sline = sr.ReadLine();

                if (sline == name)
                {
                    found = true;
                    return sline;
                }
                else
                {
                    found = false;

                }
            }
            return "not found";

        }

        public string Sort(string s)
        {

            List<int> slist = new List<int>();
            List<string> sslist = new List<string>();

            StreamReader sr = new StreamReader("testmenu.txt");
            while (!sr.EndOfStream)
            {
                int v = 0;

                string line = sr.ReadLine();
                if (Int32.TryParse(line, out v))
                {
                    slist.Add(v);
                }
                else
                {
                    sslist.Add(line);
                }
            }


            sslist.Sort();
            slist.Sort();
            Console.WriteLine("Sorterad Poang");
            foreach (var item in slist)
            {
                Console.Write(item + "\n");
            }

            Console.WriteLine("Sorterad Team");
            foreach (var item in sslist)
            {
                Console.Write(item + "\n");
            }
            return s;


        }


        public void Search_FirstName(string firstName)
        {
            bool found = false;

            for (int i = 0; i < UserList.userList.Count(); i++)
            {

                if (firstName == UserList.userList[i].firstName)
                {
                    found = true;
                    Console.WriteLine("Id: " + UserList.userList[i].id + " " + UserList.userList[i].firstName + " " + UserList.userList[i].lastName + " " + UserList.userList[i].age + " " + UserList.userList[i].nation + " " + UserList.userList[i].sex + " " + UserList.userList[i].level);
                }
                else
                {
                    found = false;
                }
            }
            if (found == false)
            {
                Console.WriteLine("Not found!");
            }
        }



       

        public void PrintList1()
        {
            foreach (var i in UserList.userList)
            {
                Console.WriteLine(i.id + " " + i.firstName + " " + i.lastName + " " + i.age + " " + i.nation + " " + i.sex + " " + i.level);
            }

        }


        public void SortFirstName()
        {
            UserList.userList.Sort(delegate(User u1, User u2)
                                   {

                                       return u1.firstName.CompareTo(u2.firstName);
                                   }
               );
        }
        public void SortLastName()
        {
            UserList.userList.Sort(delegate(User u1, User u2)
            {

                return u1.lastName.CompareTo(u2.lastName);
            }
               );
        }
        public void SortAge()
        {
            UserList.userList.Sort(delegate(User u1, User u2)
            {

                return u1.age.CompareTo(u2.age);
            }
               );
        }
        public void SortSex()
        {
            UserList.userList.Sort(delegate(User u1, User u2)
            {

                return u1.sex.CompareTo(u2.sex);
            }
               );
        }
        public void SortLevel()
        {
            UserList.userList.Sort(delegate(User u1, User u2)
            {

                return u1.level.CompareTo(u2.level);
            }
               );
        }
        public void SortNation()
        {
            UserList.userList.Sort(delegate(User u1, User u2)
            {

                return u1.nation.CompareTo(u2.nation);
            }
               );
        }
    }
}